<?php


abstract class BaseReceiptItem extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $status_id;


	
	protected $receipt_id;


	
	protected $name;


	
	protected $obj_type;


	
	protected $obj_id;


	
	protected $quantity;


	
	protected $price_of_item;


	
	protected $currency_code;


	
	protected $vat_pct;


	
	protected $tax_for_item;


	
	protected $discount_total;


	
	protected $updated_at;


	
	protected $created_at;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getStatusId()
	{

		return $this->status_id;
	}

	
	public function getReceiptId()
	{

		return $this->receipt_id;
	}

	
	public function getName()
	{

		return $this->name;
	}

	
	public function getObjType()
	{

		return $this->obj_type;
	}

	
	public function getObjId()
	{

		return $this->obj_id;
	}

	
	public function getQuantity()
	{

		return $this->quantity;
	}

	
	public function getPriceOfItem()
	{

		return $this->price_of_item;
	}

	
	public function getCurrencyCode()
	{

		return $this->currency_code;
	}

	
	public function getVatPct()
	{

		return $this->vat_pct;
	}

	
	public function getTaxForItem()
	{

		return $this->tax_for_item;
	}

	
	public function getDiscountTotal()
	{

		return $this->discount_total;
	}

	
	public function getUpdatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->updated_at === null || $this->updated_at === '') {
			return null;
		} elseif (!is_int($this->updated_at)) {
						$ts = strtotime($this->updated_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [updated_at] as date/time value: " . var_export($this->updated_at, true));
			}
		} else {
			$ts = $this->updated_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getCreatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->created_at === null || $this->created_at === '') {
			return null;
		} elseif (!is_int($this->created_at)) {
						$ts = strtotime($this->created_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [created_at] as date/time value: " . var_export($this->created_at, true));
			}
		} else {
			$ts = $this->created_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = ReceiptItemPeer::ID;
		}

	} 
	
	public function setStatusId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->status_id !== $v) {
			$this->status_id = $v;
			$this->modifiedColumns[] = ReceiptItemPeer::STATUS_ID;
		}

	} 
	
	public function setReceiptId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->receipt_id !== $v) {
			$this->receipt_id = $v;
			$this->modifiedColumns[] = ReceiptItemPeer::RECEIPT_ID;
		}

	} 
	
	public function setName($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->name !== $v) {
			$this->name = $v;
			$this->modifiedColumns[] = ReceiptItemPeer::NAME;
		}

	} 
	
	public function setObjType($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->obj_type !== $v) {
			$this->obj_type = $v;
			$this->modifiedColumns[] = ReceiptItemPeer::OBJ_TYPE;
		}

	} 
	
	public function setObjId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->obj_id !== $v) {
			$this->obj_id = $v;
			$this->modifiedColumns[] = ReceiptItemPeer::OBJ_ID;
		}

	} 
	
	public function setQuantity($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->quantity !== $v) {
			$this->quantity = $v;
			$this->modifiedColumns[] = ReceiptItemPeer::QUANTITY;
		}

	} 
	
	public function setPriceOfItem($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->price_of_item !== $v) {
			$this->price_of_item = $v;
			$this->modifiedColumns[] = ReceiptItemPeer::PRICE_OF_ITEM;
		}

	} 
	
	public function setCurrencyCode($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->currency_code !== $v) {
			$this->currency_code = $v;
			$this->modifiedColumns[] = ReceiptItemPeer::CURRENCY_CODE;
		}

	} 
	
	public function setVatPct($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->vat_pct !== $v) {
			$this->vat_pct = $v;
			$this->modifiedColumns[] = ReceiptItemPeer::VAT_PCT;
		}

	} 
	
	public function setTaxForItem($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->tax_for_item !== $v) {
			$this->tax_for_item = $v;
			$this->modifiedColumns[] = ReceiptItemPeer::TAX_FOR_ITEM;
		}

	} 
	
	public function setDiscountTotal($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->discount_total !== $v) {
			$this->discount_total = $v;
			$this->modifiedColumns[] = ReceiptItemPeer::DISCOUNT_TOTAL;
		}

	} 
	
	public function setUpdatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [updated_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->updated_at !== $ts) {
			$this->updated_at = $ts;
			$this->modifiedColumns[] = ReceiptItemPeer::UPDATED_AT;
		}

	} 
	
	public function setCreatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [created_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->created_at !== $ts) {
			$this->created_at = $ts;
			$this->modifiedColumns[] = ReceiptItemPeer::CREATED_AT;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->status_id = $rs->getInt($startcol + 1);

			$this->receipt_id = $rs->getInt($startcol + 2);

			$this->name = $rs->getString($startcol + 3);

			$this->obj_type = $rs->getInt($startcol + 4);

			$this->obj_id = $rs->getInt($startcol + 5);

			$this->quantity = $rs->getInt($startcol + 6);

			$this->price_of_item = $rs->getInt($startcol + 7);

			$this->currency_code = $rs->getString($startcol + 8);

			$this->vat_pct = $rs->getInt($startcol + 9);

			$this->tax_for_item = $rs->getInt($startcol + 10);

			$this->discount_total = $rs->getInt($startcol + 11);

			$this->updated_at = $rs->getTimestamp($startcol + 12, null);

			$this->created_at = $rs->getTimestamp($startcol + 13, null);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 14; 
		} catch (Exception $e) {
			throw new PropelException("Error populating ReceiptItem object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ReceiptItemPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			ReceiptItemPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
    if ($this->isModified() && !$this->isColumnModified(ReceiptItemPeer::UPDATED_AT))
    {
      $this->setUpdatedAt(time());
    }

    if ($this->isNew() && !$this->isColumnModified(ReceiptItemPeer::CREATED_AT))
    {
      $this->setCreatedAt(time());
    }

		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ReceiptItemPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = ReceiptItemPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += ReceiptItemPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = ReceiptItemPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ReceiptItemPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getStatusId();
				break;
			case 2:
				return $this->getReceiptId();
				break;
			case 3:
				return $this->getName();
				break;
			case 4:
				return $this->getObjType();
				break;
			case 5:
				return $this->getObjId();
				break;
			case 6:
				return $this->getQuantity();
				break;
			case 7:
				return $this->getPriceOfItem();
				break;
			case 8:
				return $this->getCurrencyCode();
				break;
			case 9:
				return $this->getVatPct();
				break;
			case 10:
				return $this->getTaxForItem();
				break;
			case 11:
				return $this->getDiscountTotal();
				break;
			case 12:
				return $this->getUpdatedAt();
				break;
			case 13:
				return $this->getCreatedAt();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = ReceiptItemPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getStatusId(),
			$keys[2] => $this->getReceiptId(),
			$keys[3] => $this->getName(),
			$keys[4] => $this->getObjType(),
			$keys[5] => $this->getObjId(),
			$keys[6] => $this->getQuantity(),
			$keys[7] => $this->getPriceOfItem(),
			$keys[8] => $this->getCurrencyCode(),
			$keys[9] => $this->getVatPct(),
			$keys[10] => $this->getTaxForItem(),
			$keys[11] => $this->getDiscountTotal(),
			$keys[12] => $this->getUpdatedAt(),
			$keys[13] => $this->getCreatedAt(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ReceiptItemPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setStatusId($value);
				break;
			case 2:
				$this->setReceiptId($value);
				break;
			case 3:
				$this->setName($value);
				break;
			case 4:
				$this->setObjType($value);
				break;
			case 5:
				$this->setObjId($value);
				break;
			case 6:
				$this->setQuantity($value);
				break;
			case 7:
				$this->setPriceOfItem($value);
				break;
			case 8:
				$this->setCurrencyCode($value);
				break;
			case 9:
				$this->setVatPct($value);
				break;
			case 10:
				$this->setTaxForItem($value);
				break;
			case 11:
				$this->setDiscountTotal($value);
				break;
			case 12:
				$this->setUpdatedAt($value);
				break;
			case 13:
				$this->setCreatedAt($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = ReceiptItemPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setStatusId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setReceiptId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setName($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setObjType($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setObjId($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setQuantity($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setPriceOfItem($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setCurrencyCode($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setVatPct($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setTaxForItem($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setDiscountTotal($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setUpdatedAt($arr[$keys[12]]);
		if (array_key_exists($keys[13], $arr)) $this->setCreatedAt($arr[$keys[13]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(ReceiptItemPeer::DATABASE_NAME);

		if ($this->isColumnModified(ReceiptItemPeer::ID)) $criteria->add(ReceiptItemPeer::ID, $this->id);
		if ($this->isColumnModified(ReceiptItemPeer::STATUS_ID)) $criteria->add(ReceiptItemPeer::STATUS_ID, $this->status_id);
		if ($this->isColumnModified(ReceiptItemPeer::RECEIPT_ID)) $criteria->add(ReceiptItemPeer::RECEIPT_ID, $this->receipt_id);
		if ($this->isColumnModified(ReceiptItemPeer::NAME)) $criteria->add(ReceiptItemPeer::NAME, $this->name);
		if ($this->isColumnModified(ReceiptItemPeer::OBJ_TYPE)) $criteria->add(ReceiptItemPeer::OBJ_TYPE, $this->obj_type);
		if ($this->isColumnModified(ReceiptItemPeer::OBJ_ID)) $criteria->add(ReceiptItemPeer::OBJ_ID, $this->obj_id);
		if ($this->isColumnModified(ReceiptItemPeer::QUANTITY)) $criteria->add(ReceiptItemPeer::QUANTITY, $this->quantity);
		if ($this->isColumnModified(ReceiptItemPeer::PRICE_OF_ITEM)) $criteria->add(ReceiptItemPeer::PRICE_OF_ITEM, $this->price_of_item);
		if ($this->isColumnModified(ReceiptItemPeer::CURRENCY_CODE)) $criteria->add(ReceiptItemPeer::CURRENCY_CODE, $this->currency_code);
		if ($this->isColumnModified(ReceiptItemPeer::VAT_PCT)) $criteria->add(ReceiptItemPeer::VAT_PCT, $this->vat_pct);
		if ($this->isColumnModified(ReceiptItemPeer::TAX_FOR_ITEM)) $criteria->add(ReceiptItemPeer::TAX_FOR_ITEM, $this->tax_for_item);
		if ($this->isColumnModified(ReceiptItemPeer::DISCOUNT_TOTAL)) $criteria->add(ReceiptItemPeer::DISCOUNT_TOTAL, $this->discount_total);
		if ($this->isColumnModified(ReceiptItemPeer::UPDATED_AT)) $criteria->add(ReceiptItemPeer::UPDATED_AT, $this->updated_at);
		if ($this->isColumnModified(ReceiptItemPeer::CREATED_AT)) $criteria->add(ReceiptItemPeer::CREATED_AT, $this->created_at);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(ReceiptItemPeer::DATABASE_NAME);

		$criteria->add(ReceiptItemPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setStatusId($this->status_id);

		$copyObj->setReceiptId($this->receipt_id);

		$copyObj->setName($this->name);

		$copyObj->setObjType($this->obj_type);

		$copyObj->setObjId($this->obj_id);

		$copyObj->setQuantity($this->quantity);

		$copyObj->setPriceOfItem($this->price_of_item);

		$copyObj->setCurrencyCode($this->currency_code);

		$copyObj->setVatPct($this->vat_pct);

		$copyObj->setTaxForItem($this->tax_for_item);

		$copyObj->setDiscountTotal($this->discount_total);

		$copyObj->setUpdatedAt($this->updated_at);

		$copyObj->setCreatedAt($this->created_at);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new ReceiptItemPeer();
		}
		return self::$peer;
	}

} 